<?php
/***********************************************************
 * Copyright (C) 2010-2012 by Lifire
 * All rights reserved.
 * 
 * Filename: 
 * Description: 
 * 
 * Created by Lifire at 2010-11-18
 * Email:yunzhi.li.08@gmail.com
 ***********************************************************
 */
 ?>
<?php

class OrderAction extends Action 
{
	public function _initialize()
	{
		$this->assign('jumpUrl',__URL__);
 		if(!isset($_SESSION['adminid']))
 		{ 
 			 $url=__APP__.'/Index/login';
 			 redirect($url);return;
 		}		
	}  
	public function index()
	{
		$Order=D("Order");
		$count=$Order->count();
		import("ORG.Util.Page");
		$listRows=15;
		$p=new page($count,$listRows);
		$list=$Order->findAll(null,'*','addtime desc',$p->firstRow.','.$p->listRows);
		$page=$p->show();
		if ($list!==false) 
		{
			$this->assign('page',$page);
			$this->assign('list',$list);
		}
		$this->display();		
	}
	public function view()
	{
		$id=isset($_GET['id'])?(int)($_GET['id']):0;
		$temp=D("Order")->find($id);
		if($id==0 || !$temp)
		{
			$this->redirect();return;
		}
		$this->assign('vo',$temp);
		$this->display();
	}
	public function reply()
	{
		if(!$this->isPost())
		{
			$id=isset($_GET['id'])?(int)($_GET['id']):0;
			$temp=D("Order")->find($id);
			if($id==0 || !$temp)
			{
				$this->redirect();return;
			}
			$this->assign('vo',$temp);			
			$this->display();
		}
		else
		{
			$id=isset($_POST['id'])?(int)($_POST['id']):0;
			$reply=isset($_POST['reply'])?trim($_POST['reply']):'';
			if($id==0)
			{
				$this->redirect();return;
			}
			if($reply=='')
			{
				$msg="跟进状态不能为空";
				$this->error($msg);return;
			}
			$data=array('id'=>$id,'reply'=>$reply,'replytime'=>time(),'replyer'=>$_SESSION['username']);
			$Order=D("Order");
			if(!$Order->create($data))
			{
				$this->error($Order->getError());return;
			}
			if(!$Order->save())
			{
				$msg="跟进出错";
				$this->error($msg);return;
			}
			$msg="跟进成功";
			$this->assign('jumpUrl',__URL__);
			$this->success($msg);
		}
	}
	public function del()
	{
		$id=isset($_GET['id'])?(int)($_GET['id']):0;
		if (!$id){ $this->error(L('_SELECT_NOT_EXIST_'));return;}
		$Order=D("Order");
		$list=$Order->find($id);
		if (!$list){ $this->error(L('_SELECT_NOT_EXIST_'));return;}
		if(!$Order->deleteById($id)){
			$this->error(L('_DELETE_FAIL_'));return;
		}
		$this->redirect();		
	}
}
?>